home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*
- * octenv -
- * Project an environment onto a cylinder
- *
- * Paul Haeberli - 1988
- */
- #include "texture.h"
-
- #define DIV 1
- #define PI (3.1415926535)
-
- TEXTURE *tm;
- int size, samples;
-
- main(argc,argv)
- int argc;
- char **argv;
- {
- float vr, vg, vb;
- float tr, tg, tb;
- int x, y;
- IMAGE *image;
- int i;
- vect pos, c;
- int xsize, ysize;
- short *rbuf, *gbuf, *bbuf;
-
- if(argc<5) {
- fprintf(stderr,"usage: clyenv size samples file.env file.rgb\n");
- exit(1);
- }
- size = atoi(argv[1]);
- samples = atoi(argv[2]);
- tm = tmopen(argv[3]);
- if(!tm) {
- printf("can't open environment map.\n");
- exit(1);
- }
- xsize = size;
- ysize = size;
- rbuf = (short *)malloc(xsize*sizeof(short));
- gbuf = (short *)malloc(xsize*sizeof(short));
- bbuf = (short *)malloc(xsize*sizeof(short));
- image = iopen(argv[4],"w",RLE(1),3,xsize,ysize,3);
- for(y=0; y<ysize; y++) {
- for(x=0; x<size; x++) {
- tr = tg = tb = 0.0;
- for(i=0; i<samples; i++) {
- if(samples>1) {
- pos.x = (x+frand())/xsize;
- pos.y = (y+frand())/ysize;
- pos.z = 0;
- } else {
- pos.x = (float)x/xsize;
- pos.y = (float)y/ysize;
- pos.z = 0.0;
- }
- shadecly(&pos,&c);
- tr += c.x;
- tg += c.y;
- tb += c.z;
- }
- rbuf[x] = 255*tr/samples;
- gbuf[x] = 255*tg/samples;
- bbuf[x] = 255*tb/samples;
- }
- putrow(image,rbuf,y,0);
- putrow(image,gbuf,y,1);
- putrow(image,bbuf,y,2);
- tpercentdone(100.0*y/(ysize-1));
- }
- iclose(image);
- }
-
- float sinewarp(v)
- float v;
- {
- return sin(v*(PI/2.0));
- }
-
- shadecly(p,c)
- vect *p, *c;
- {
- float angle;
- vect v;
- float dx, dy, mag;;
-
- #ifdef SDFSDF
- p->x /= 2.0;
- p->y = ((p->y-0.5)/2)+0.5;
- #endif
-
- dx = 1.0/(2*PI);
- dy = p->y-0.5;
- mag = sqrt(dx*dx+dy*dy);
- dx /= mag;
- dy /= mag;
-
- angle = 2*PI*p->x;
- v.x = dx*sin(angle);
- v.y = dx*cos(angle);
- v.z = dy;
- envsample(tm,&v,c);
- }
-